package edu.seu.shuai;

import com.alibaba.fastjson.JSON;
import com.github.houbb.heaven.util.util.DateUtil;
import edu.seu.shuai.core.MQConsumerPush;
import edu.seu.shuai.core.MQProducer;
import edu.seu.shuai.dto.MQMessage;
import edu.seu.shuai.dto.SendResult;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Chapter2Test {
    public static void main(String[] args) {
        MQConsumerPush mqConsumerPush = new MQConsumerPush();
        mqConsumerPush.start();

        MQProducer mqProducer = new MQProducer();
        mqProducer.start();

//等待启动完成
        while (!mqProducer.isEnableFlag()) {
            System.out.println("等待初始化完成...");
            DateUtil.sleep(100);
        }

        String message = "HELLO MQ!";
        MQMessage mqMessage = new MQMessage();
        mqMessage.setTopic("TOPIC");
        mqMessage.setTags(Arrays.asList("TAGA", "TAGB"));
        mqMessage.setPayload(Arrays.toString(message.getBytes(StandardCharsets.UTF_8)));

        SendResult sendResult = mqProducer.send(mqMessage);
        System.out.println(JSON.toJSON(sendResult));
    }
}
